package com.sqs.controller;


import com.sqs.constant.ResultConstant;
import com.sqs.dto.KnowledgeFileInsertDTO;
import com.sqs.dto.KnowledgeFileUpdateDTO;
import com.sqs.result.Result;
import com.sqs.service.IKnowledgeFileService;
import com.sqs.vo.KnowledgeFileVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/knowledgefile")
public class KnowledgeFileController {

    @Autowired
    private IKnowledgeFileService iKnowledgeFileService;

    /**
     * 查询知识库内所有的知识文件
     * @param repositoryId
     * @return
     */
    @GetMapping
    public Result<List<KnowledgeFileVO>> knowledgeFileSelect(Long repositoryId){
        log.info("查询该知识库的所有知识文件：{}", repositoryId);
        return Result.success(ResultConstant.SEARCH_SUCCESS, iKnowledgeFileService.knowledgeFileSelect(repositoryId));
    }

    /**
     * 向知识库添加文件
     * @param knowledgeFileInsertDTO
     * @return
     * */
    @PostMapping
    public Result<KnowledgeFileVO> knowledgeFileInsert(@RequestBody KnowledgeFileInsertDTO knowledgeFileInsertDTO){
        log.info("向知识库添加文件：{}", knowledgeFileInsertDTO);
        return Result.success(ResultConstant.ADD_SUCCESS, iKnowledgeFileService.knowledgeFileInsert(knowledgeFileInsertDTO));
    }

    /**
     * 删除知识文件
     * @param id
     * @return
     * */
    @DeleteMapping
    public Result knowledgeFileDelete(Long id){
        log.info("删除文件：{}", id);
        iKnowledgeFileService.knowledgeFileDelete(id);
        return Result.success(ResultConstant.DELETE_SUCCESS);
    }

    /**
     * 修改知识文件名称
     * @param knowledgeFileUpdateDTO
     * @return
     * */
    @PutMapping
    public Result knowledgeFileUpdate(KnowledgeFileUpdateDTO knowledgeFileUpdateDTO){
        log.info("修改文件信息：{}", knowledgeFileUpdateDTO);
        iKnowledgeFileService.knowledgeFileUpdate(knowledgeFileUpdateDTO);
        return Result.success(ResultConstant.UPDATE_SUCCESS);
    }

}
